//
//  LRTopView.swift
//  LRWeibo
//
//  Created by admin on 15/9/26.
//  Copyright © 2015年 懒人. All rights reserved.
//

import UIKit

class LRTopView: UIView {

    var viewModel: LRStatusListModel?{
    
        didSet{
            
            // 设置变量
            iconView.sd_setImageWithURL(viewModel?.user_icon)
            nameLabel.text = viewModel?.user?.screen_name
            commonView.image = viewModel?.commonImage
            vipView.image = viewModel?.vipImage
            timeLabel.text = viewModel?.created_at
            sourceLabel.text = viewModel?.source
            // 约束UI
            setUI()
        }
    }
    
     // MARK: - UI约束
    private func setUI()
    {
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(commonView)
        addSubview(vipView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        
        // 自动布局
        iconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(snp_top).offset(LRStatusCellMargin)
            make.left.equalTo(snp_left).offset(LRStatusCellMargin)
            make.width.equalTo(LRStatusCellIconWidth)
            make.height.equalTo(LRStatusCellIconWidth)
        }
        
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView.snp_top)
            make.left.equalTo(iconView.snp_right).offset(LRStatusCellMargin)
        }
        
        commonView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(nameLabel.snp_top)
            make.left.equalTo(nameLabel.snp_right).offset(LRStatusCellMargin)
        }
        
        vipView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_right)
            make.centerY.equalTo(iconView.snp_top)
        }
        
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView.snp_bottom).offset(LRStatusCellMargin)
            make.left.equalTo(iconView.snp_left)
        }
        
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(timeLabel.snp_top)
            make.left.equalTo(timeLabel.snp_right).offset(LRStatusCellMargin)
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = UIColor.whiteColor()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
     // MARK: - 控件懒加载
    /// 头像
    private lazy var iconView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    /// 姓名
    private lazy var nameLabel: UILabel = UILabel(title: "企鹅", color: UIColor.darkGrayColor(), fontSize: 14)
    /// 会员
    private lazy var commonView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_expired"))
    /// vip
    private lazy var vipView: UIImageView = UIImageView(image: UIImage(named: "avatar_grassroot"))
    /// 时间
    private lazy var timeLabel: UILabel = UILabel(title: "刚刚", color: UIColor.orangeColor(), fontSize: 10)
    /// 来源
    private lazy var sourceLabel: UILabel = UILabel(title: "腾讯微博", color: UIColor.darkGrayColor(), fontSize: 10)

}
